package com.atguigu.spzx.order.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.order.OrderInfo;
import com.atguigu.spyx.model.dto.h5.OrderInfoDto;
import com.atguigu.spyx.model.vo.h5.OrderInfoVo;
import com.atguigu.spzx.order.service.OrderInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2023-11-21-19:51
 */
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {

    @Resource
    OrderInfoService orderInfoService;
    @Operation(summary = "去结算：确认下单接口")
    @GetMapping("/auth/trade")
    public Result trade(){
        OrderInfoVo orderInfoVo = orderInfoService.trade();
        return Result.ok().data(orderInfoVo);
    }

    @Operation(summary = "订单确认页：提交订单接口")
    @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestBody OrderInfoDto orderInfoDto){
        Long orderId = orderInfoService.submitOrder(orderInfoDto);
        return Result.ok().data(orderId);
    }

    @GetMapping("/auth/{orderId}")
    public Result findOrderById(@PathVariable("orderId")Long orderId){
        OrderInfo orderInfo = orderInfoService.findOrderById(orderId);
        return Result.ok().data(orderInfo);
    }

    @GetMapping("/auth/{pageNum}/{pageSize}")
    public Result orderPage(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            Integer orderStatus){
        PageInfo<OrderInfo> pageInfo = orderInfoService.orderPage(pageNum,pageSize,orderStatus);
        return Result.ok().data(pageInfo);
    }

    @GetMapping("/auth/buy/{skuId}")
    public Result buy(@PathVariable("skuId")Long skuId){
        OrderInfoVo orderInfoVo  = orderInfoService.buy(skuId);
        return Result.ok().data(orderInfoVo);
    }

    @GetMapping("/findOrder/{orderNo}")
    public Result findOrderByOrderNo(@PathVariable("orderNo")Long orderNo){
        OrderInfo orderInfo = orderInfoService.findOrderByNo(orderNo);
        return Result.ok().data(orderInfo);
    }

    @GetMapping("/updatePayStatus/{orderNo}/{payType}/{payStatus}")
    public Result updatePayStatus(@PathVariable("orderNo")Long orderNo,
                                  @PathVariable("payType")Long payType,
                                  @PathVariable("payStatus")Long payStatus){
        orderInfoService.updatePayStatus(orderNo,payType,payStatus);
        return Result.ok();
    }


}
